﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AdflyBot
{
        public static class EasyTimer
        {
            public static System.Timers.Timer timer;



            public static IDisposable SetInterval(Action method, int delayInMilliseconds)
            {
                timer = new System.Timers.Timer(delayInMilliseconds);
                timer.Elapsed += (source, e) =>
                {
                    method();
                };

                timer.Enabled = true;
                timer.Start();

                // Returns a stop handle which can be used for stopping
                // the timer, if required
                return timer as IDisposable;
            }

            public static IDisposable SetTimeout(Action method, int delayInMilliseconds)
            {
                System.Timers.Timer timer = new System.Timers.Timer(delayInMilliseconds);
            
                timer.Elapsed += (source, e) =>
                {
                    method();
                };

                timer.AutoReset = false;
                timer.Enabled = true;
                timer.Start();

                // Returns a stop handle which can be used for stopping
                // the timer, if required
                return timer as IDisposable;
            }
        }
}
